﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Xunit;

namespace UniSender.Test
{
    static class TestUtility
    {
        public static IDictionary<string, string> ParseQuery(string s)
        {
            var query = HttpUtility.ParseQueryString(s);
            return query.AllKeys.ToDictionary(k => k, k => query[k]);
        }

        public static void CompareUrlPath(Uri expected, Uri actual)
        {
            Assert.Equal(expected.GetLeftPart(UriPartial.Path), actual.GetLeftPart(UriPartial.Path));
        }

        public static void CompareUrlQuery(string expected, string actual)
        {
            Assert.Equal(ParseQuery(expected), ParseQuery(actual));
        }

        public static void CompareUrl(Uri expected, Uri actual)
        {
            CompareUrlPath(expected, actual);
            CompareUrlQuery(expected.Query, actual.Query);
        }
    }
}
